
	****************************************************************
	*
	*  		      REPLICATION FILES 
	*					for
	*  "PRO-GOVERNMENT MILITIAS AND CONFLICT"
	*
	*  Sabine C. Carey, University of Mannheim
	*  Neil J. Mitchell, University College London
	*  Adam Scharpf, University of Copenhagen + GIGA
	*
	****************************************************************
	* Author: Adam Scharpf
	* Date:	  07/03/2022
	* 
	* Data files (Stata 16.1):
	* 1) "pgmcoin_1950_2005_ts.dta" (time-series dataset)
	* 2) "pgmcoin_1950_2005_cs.dta" (cross-sectional dataset) 
	*
	* When using the data, please cite: 
	* Carey, Sabine C., Neil J. Mitchell, and Adam Scharpf. 2022. "Pro-Government Militias and Conflict.'' 
	* Oxford Research Encyclopedia of Politics, DOI: https://doi.org/10.1093/acrefore/9780190228637.013.33
	*
	****************************************************************
	
	
	clear all
	
	****************************************************************
	* Loading data
	****************************************************************	
		
	*Storing working path in macro - NOTE: Change this path to location of replication folder
	global datapath="C:\Users\adam.scharpf\Dropbox\PGMCOINDuration\Replication_Careyetal2022_ORE"

		
	****************************************************************
	* FIGURE 3
	****************************************************************	

	*Loading TSCS data
	use "$datapath\pgmcoin_1950_2005_ts.dta"	
	
	*Graph: Pro-government militias in counterinsurgency wars, 1950–2005
	#delimit ;
	twoway (line pgmperc year,
			lcolor(black) lpattern(solid)
			)
		   (line localperc year, 
			lcolor(black) lpattern(shortdash)
			)
		   (line semiperc year, 
			lcolor(black) lpattern(dot)	lwidth(*1.2)
			)
	,
	xline(1989, lcolor(gs8) lpattern(solid) lwidth(*1))
	ttext(102 1988 "End of" "Cold War", size(*.85) color(gs8) placement(west))
	xsize(1.3)
	ysize(1)
	xscale(range(1950 2006) noextend titlegap(+2))
	yscale(range(0 103) noextend titlegap(+2))	   
	ylabel(0(20)100, angle(horizontal) nogrid)
	yticks(0(10)100, tlength(*.5))
	xlabel(1950(10)2005,)
	xticks(1950(5)2005, tlength(*.5))
	ytitle("Percentage of wars")
	xtitle("")
	legend(
		order(1 "PGM" 2 "Local PGM" 3 "Semi-official PGM")
		size(*1) keygap(*0.5) symxsize(*.5) symysize(*.5) region(lcolor(white))
		rows(1)
		position(6) //ring(0) bmargin(0 0 +2 0)
		
	)	
	plotregion(lcolor(white)) 
	graphregion(color(white) lcolor(white) lalign(outside))	
	;
	#delimit cr	
	graph export "$datapath\Figure3.pdf", as(pdf) replace		
	
	
	****************************************************************
	* FIGURE 4
	****************************************************************	
		
	*Loading CS data
	use "$datapath\pgmcoin_1945_2005_cs.dta"			
		
	*Graph: The timing of PGM occurrence during counterinsurgency wars, 1945–2005
	#delimit ;
	hist pgm_stperc, bin(10) percent
		fcolor(gs12) lcolor(black) lwidth(*.5)
		ysize(1)
		xsize(1.25)
		xscale(range(0 100) noextend titlegap(+2))
		yscale(range(0 ) noextend titlegap(0))	   
		ylabel(0(20)100, angle(horizontal) nogrid)
		ytick(0(10)100, tlength(*.5))
		xlabel(0(10)100)		
		ytitle("Percentage of wars")
		xtitle("Occurrence of PGM during conflict" "(standardized)")
		plotregion(lcolor(white)) 
		graphregion(color(white) lcolor(white) lalign(outside))	
	;
	#delimit cr
	graph export "$datapath\Figure4.pdf", as(pdf) replace	
	
	
	****************************************************************
	* FIGURE 5
	****************************************************************	
					
	*Graph: Counterinsurgency war duration with and without local PGMs, 1945–2005
	#delimit ;
	sts graph, ci by(loc_pgm)
		plot1opts(lpattern(shortdash) lcolor(black))
		plot2opts(lpattern(solid) lcolor(black))
		ci1opts(fcolor(gs10%50) fintensity(100) lcolor(none) lalign(inside))
		ci2opts(fcolor(gs10%50) fintensity(100) lcolor(none) lalign(inside))
		ysize(1)
		xsize(1.25)
		xscale(range(0 600) noextend titlegap(+2))
		yscale(range(0 1) noextend titlegap(+2))	   
		ylabel(0(.2)1, angle(horizontal) nogrid)
		xlabel(0(100)600)
		xticks(0(50)600, tlength(*.5))
		xtitle("War duration (in months)")	
		ytitle("Probability of war continuing")			
		legend(
		order(6 "Local PGM" 5 "No local PGM" 1 "95% CI")
		size(*1) keygap(*0.5) symxsize(*.5) symysize(*.5) region(lcolor(white))
		cols(1)
		position(2) ring(0) bmargin(0 0 0 +.5)	
		)		
		title("")
		plotregion(lcolor(white)) 
		graphregion(color(white) lcolor(white) lalign(outside))	
	;
	#delimit cr
	graph export "$datapath\Figure5.pdf", as(pdf) replace				
	

	****************************************************************
	* FIGURE 6
	****************************************************************
	
	*******************************
	* Preparing data for PGMS
	*******************************
	
	*Preserving data
	preserve
		
	*Keeping terminated COIN wars 
	keep if coinend==1 
	
	*Aggregating wars by PGM presence and COIN outcomes
	collapse (sum) coinend, by(pgm outcome) 

	*Calculating percentages
	bysort pgm (outcome): egen total=total(coinend)
	gen perc=(coinend/total)*100
	bysort pgm (outcome): gen perc_sum=sum(perc)	
		
	*Reshaping data
	drop coinend total perc
	reshape wide perc_sum@, i(pgm) j(outcome)
	gen perc_sum=0
	
	*Saving data
	save "$datapath\waroutcomes_allpgm.dta", replace
	
	*Restoring data
	restore
	
	*******************************
	* Preparing data for local PGMs
	*******************************	
	
	*Preserving data
	preserve
	
	*Keeping terminated COIN wars
	keep if coinend==1 	
	
	*Aggregating wars by local PGM presence and COIN outcomes
	collapse (sum) coinend, by(loc_pgm outcome) 

	*Calculating percentages
	bysort loc_pgm (outcome): egen total=total(coinend)
	gen perc=(coinend/total)*100
	bysort loc_pgm (outcome): gen perc_sum=sum(perc)	
		
	*Reshaping data
	drop coinend total perc
	reshape wide perc_sum@, i(loc_pgm) j(outcome)
	gen perc_sum=0
	
	*Preparing Local PGM variable
	rename loc_pgm pgm
	replace pgm=-1 if pgm==1
	replace pgm=-2 if pgm==0
	
	*Appending data
	append using "$datapath\waroutcomes_allpgm.dta"	
	
	*Sorting PGM variable
	sort pgm
	
	*Generating y-axis
	gen yaxis=1 if pgm==1		//PGM
	replace yaxis=.8 if pgm==0	//NO PGM
	replace yaxis=.5 if pgm==-1	//LOCAL PGM
	replace yaxis=.3 if pgm==-2	//NO LOCAL PGM
	
	*Graph: The outcome of counterinsurgency wars with and without PGMs, 1945–2005
	#delimit ;		
	twoway (rbar perc_sum perc_sum0 yaxis, 
			horizontal barwidth(.1) fcolor(gs4) lcolor(black) lwidth(*.5) lalign(inside)
			)
			(rbar perc_sum0 perc_sum1 yaxis, 
			horizontal barwidth(.1) fcolor(gs8) lcolor(black) lwidth(*.5) lalign(inside)
			)			
			(rbar perc_sum1 perc_sum2 yaxis, 
			horizontal barwidth(.1) fcolor(gs12) lcolor(black) lwidth(*.5) lalign(inside)
			)
			,
		yscale(range(0.1 1.2) noextend)
		xscale(range(0 100) noextend titlegap(+3.5))
		ylabel(.3 "No local PGM" .5 "Local PGM" .8 "No PGM" 1 "PGM", angle(horizontal) nogrid)
		xlabel(0(10)100)
		ytitle("")
		xtitle("Percentage of wars")
		legend(
				order(1 "Loss" 2 "Draw" 3 "Win" )				
				size(*1) keygap(*0.75) symxsize(*1) symysize(*1) region(lcolor(white))
				rows(1)
				position(6) bmargin(0 0 0 3.5)				
		)		
		plotregion(lcolor(white)) 
		graphregion(color(white) lcolor(white) lalign(outside))	
	;
	#delimit cr		
	graph export "$datapath\Figure6.pdf", as(pdf) replace
	
	*Deleting temporary data
	erase "$datapath\waroutcomes_allpgm.dta"	
	